package swing.chapter01;

import javax.swing.*;
import java.awt.*;
import java.util.concurrent.TimeUnit;

/**
 * 04，程序中的所有 UI 操作都遵守这种通过 SwingUtilities.invokeLater() 方式来提交操作
 */
public class SubmitSwingProgram extends JFrame {
    static SubmitSwingProgram ssp;

    JLabel label;

    public SubmitSwingProgram() throws HeadlessException {
        super("Hello Swing");

        label = new JLabel("3 秒钟后会发生了变化");
        add(label);
        setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);
        setSize(300, 300);
        setVisible(true);
    }

    public static void main(String[] args) throws InterruptedException {
        SwingUtilities.invokeLater(new Runnable() {
            @Override
            public void run() {
                ssp = new SubmitSwingProgram();
            }
        });

        TimeUnit.SECONDS.sleep(1);

        SwingUtilities.invokeLater(new Runnable() {
            @Override
            public void run() {
                ssp.label.setText("\t ^_^   修改啦");
            }
        });
    }
}
